package activity;

import com.qzhy.female.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.ShareContent;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMusic;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MamaActivity extends BaseActivity implements OnClickListener {

	private Button mBtn_WL;
	private Button mBtn_QQ;
	private Button mBtn_WX;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mama);
		InitUI();
	}

	private void InitUI() {
		mBtn_WL = (Button) findViewById(R.id.btn_xl);
		mBtn_WL.setOnClickListener(this);
		mBtn_QQ = (Button) findViewById(R.id.btn_qq);
		mBtn_QQ.setOnClickListener(this);
		mBtn_WX = (Button) findViewById(R.id.btn_wx);
		mBtn_WX.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		UMImage image = new UMImage(MamaActivity.this, "http://www.umeng.com/images/pic/social/integrated_3.png");
        UMusic music = new UMusic("http://music.huoxing.com/upload/20130330/1364651263157_1085.mp3");
        music.setTitle("sdasdasd");
        music.setThumb(new UMImage(MamaActivity.this,"http://www.umeng.com/images/pic/social/chart_1.png"));
        UMVideo video = new UMVideo("http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html");
		switch (v.getId()) {
		case R.id.btn_xl:
			new ShareAction(this).setPlatform(SHARE_MEDIA.SINA).setCallback(umShareListener)
            .withText("hello umeng video")
            .withTargetUrl("http://www.baidu.com")
            .withMedia(image)
            .share();
			break;
		case R.id.btn_qq:
			 new ShareAction(this).setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.QZONE,SHARE_MEDIA.WEIXIN,SHARE_MEDIA.WEIXIN_CIRCLE)
             .setContentList(new ShareContent(),new ShareContent())
             .withMedia(image)
             .setListenerList(umShareListener,umShareListener)
             .open();
			break;
		case R.id.btn_wx:
			 new ShareAction(this).setPlatform(SHARE_MEDIA.WEIXIN).setCallback(umShareListener)
             .withText("hello wx")
             .withMedia(video)
             .share();
			break;
		default:
			break;
		}
	}
	 private UMShareListener umShareListener = new UMShareListener() {
	        @Override
	        public void onResult(SHARE_MEDIA platform) {
	            Toast.makeText(MamaActivity.this, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
	        }

	        @Override
	        public void onError(SHARE_MEDIA platform, Throwable t) {
	            Toast.makeText(MamaActivity.this,platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
	        }

	        @Override
	        public void onCancel(SHARE_MEDIA platform) {
	            Toast.makeText(MamaActivity.this,platform + " 分享取消了", Toast.LENGTH_SHORT).show();
	        }
	    };
	    private ShareBoardlistener shareBoardlistener = new ShareBoardlistener() {

	        @Override
	        public void onclick(SnsPlatform snsPlatform,SHARE_MEDIA share_media) {
	            new ShareAction(MamaActivity.this).setPlatform(share_media).setCallback(umShareListener)
	                    .withText("多平台分享")
	                    .share();
	        }
	    };
	    @Override
	    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	        super.onActivityResult(requestCode, resultCode, data);
	        /** attention to this below ,must add this**/
	        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

	    }
}
